package com.grf.hadoop.temp_grouping;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class TempMapper extends Mapper<LongWritable, Text, TempBean, NullWritable> {

    private TempBean k = new TempBean();

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        String line = value.toString();
        String[] fields = line.split(" ");
        k.setYear(fields[0]);
        k.setTemp(Double.parseDouble(fields[1]));
        context.write(k, NullWritable.get());
    }
}
